<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
class IndexController extends Controller
{
    //
    public function index()
    {
        return view('home.index.index',['title' =>'主页']);
    }
    // public function shopindex()
    // {   
    //     // $data_goods = DB::table('goods') -> where('gid',$gid) -> first();
    //     $data = DB::table('category') -> where('pid','=','0')-> get();
    //     // dd($data);
       
    //     return view('home.index.shopindex',['title' => '商城','data' => $data]);

    // }
       public function shopindex($pid)
    {
       $cateData = DB::table('category') -> where("pid", $pid) -> get();
        
        $data = [];
        foreach ($cateData as $key => $value) {
            $value -> sub = $this -> shopindex($value -> id);
            $data[] = $value;

        }
        return $data;           

    }
    public function test()
    {
        $res  = $this -> shopindex(0);
        
        //友情链接
        $link = DB::table('admin_link')->get();
       return view('home.index.shopindex',['title' => '你好','res' => $res,'link'=>$link]);
    }
    
}
